package com.ltedu.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @className: BigDecimalJsonSerializer
 * @auther: Jerry
 * @date: 2020/12/8 17:06
 * @desctiption: TODO
 * @version: 1.0
 */
public class BigDecimalJsonSerializer extends JsonSerializer<BigDecimal> {

    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String text = (bigDecimal == null ? null : String.valueOf(bigDecimal));
        if (text != null) {
            jsonGenerator.writeString(text);
        }
    }
}
